using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace DocLibApp
{
    public partial class UC_DocList : UserControl
    {
        public UC_DocList()
        {
            InitializeComponent();
        }

        private void lsv_Result_DoubleClick(object sender, EventArgs e)
        {
            if (lsv_Result.SelectedItems.Count > 0 && lsv_Result.SelectedItems[0].Tag != null)
            {
                string doc_id = lsv_Result.SelectedItems[0].Tag.ToString().Trim();

                FormDocument fdc = new FormDocument();
                fdc.OpenDocument(doc_id);
                fdc.Show();
            }
        }

        private void addDocumentToBatchProcessToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lsv_Result.SelectedItems.Count > 0 && lsv_Result.SelectedItems[0].Tag != null)
            {
                string doc_id = lsv_Result.SelectedItems[0].Tag.ToString().Trim();

                foreach (System.Windows.Forms.Form aChild in FormMain.DocLibFormMain.MdiChildren)
                {
                    if (aChild.GetType().FullName.IndexOf("FormBatchProcess") > -1)
                    {
                        //aChild.BringToFront();
                        (aChild as FormBatchProcess).AddDocumentToList(doc_id);
                        return;
                    }
                }

                //if the form does not exist
                FormBatchProcess fbp = new FormBatchProcess();
                fbp.MdiParent = FormMain.DocLibFormMain;
                fbp.TopLevel = true;
                fbp.AddDocumentToList(doc_id);
                fbp.Show();
            }
        }
    }
}
